<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <link href="../style/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="../style/summernote.css" rel="stylesheet">
    <link href="../style/summernote-bs3.css" rel="stylesheet">
    <link href="../style/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="../style/sweetalert.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../style/bootstrap-treeview.min.css">
    <script src="../js/env.js"></script>
    <style>
    </style>
</head>
<body style="background-color: rgb(243,243,244); height: 100%">
<div class="container" style="margin: 0; width: 100%; padding-left: 20px;">
    <div class="row" style="padding: 10px">
        <a href="modelList.html">范本管理</a>>><span>风险点管理</span>
    </div>
    <div class="row">
        <div class="col-md-5">
            <div class="panel panel-primary ">
                <div class="panel-heading">
                    <h3 class="panel-title">范本原文</h3>
                </div>
                <div class="panel-body right_centent" id="content" style="overflow: auto;">
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="panel panel-primary ">
                <div class="panel-heading">
                    <h3 class="panel-title">范本条款目录</h3>
                </div>
                <div class="panel-body right_centent" style="overflow: auto;">
                    <div id="left-tree"></div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="panel panel-primary ">
                <div class="panel-heading">
                    <h3 class="panel-title">风险点内容</h3>
                </div>
                <div class="panel-body right_centent">
                    <div class="form-group">
                        <p>选中条款:</p>
                        <input id="editName" type="text" class="form-control" autocomplete="off"/>
                    </div>
                    <input hidden name="itemIndex">
                    <input hidden name="riskId">
                    <div class="form-group">
                        <p>条款名称:</p>
                        <input class="form-control" name="itemName">
                    </div>
                    <div class="form-group">
                        <input type="radio" value="1" name="riskType" id="item" checked/><label for="item"> &nbsp;审查建议
                        &nbsp;</label>
                        <input type="radio" value="2" name="riskType" id="prop"/><label for="prop"> &nbsp;履约提示&nbsp;</label>
                        <input type="radio" value="3" name="riskType" id="subj"/><label for="subj"> &nbsp;主体审查</label>
                    </div>
                    <div class="form-group">
                        <textarea style="width: 100%;height: 300px"></textarea>
                    </div>
                    <div class="form-group" style="text-align: center;">
                        <button onclick="submitAdd()" class="btn-primary btn">提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../js/jquery.min.js?v=2.1.4"></script>
<script src="../js/bootstrap.min.js?v=3.3.6"></script>
<script type="text/javascript" src="../js/bootstrap-treeview.js"></script>
<script src="../js/summernote.min.js"></script>
<script src="../js/summernote-zh-CN.js"></script>
<script src="../js/sweetalert.min.js"></script>
<script type="text/javascript">
    var modelId = localStorage["modelId"];

    function submitAdd() {
        var adviseName = "";
        var riskType = $('input:radio[name="riskType"]:checked').val();
        if (riskType == 1) {
            adviseName = "adviseRe";
        } else if (riskType == 2){
            adviseName = "performance";
        }else{
            adviseName = "subjectReview"
        }
        var riskId = $("input[name=riskId]").val();
        var itemIndex = $("input[name=itemIndex]").val();
        var itemName = $("input[name=itemName]").val();
        var adviseValue = $("textarea").val();
        var param = {
            "riskId": riskId, "modelId": modelId, "itemIndex": itemIndex,
            "itemName": itemName, adviseName: adviseValue
        };
        param[adviseName] = adviseValue;
        $.post(requestUrl+"/risk/editRisk", param, function (data) {
            if (data.result == true) {
                swal({title: "完成", text: "风险点提交成功", type: "success", closeOnConfirm: true});
                $("input[name=riskId]").val(data.riskId);
            } else {
                swal({title: "添加失败", text: "请检查内容是否缺失", type: "error", closeOnConfirm: true});
            }


        });
    }

    $(function () {
        var winHeight;
        if (window.innerHeight) {
            winHeight = window.innerHeight;
        } else if ((document.body) && (document.body.clientHeight)) {
            winHeight = document.body.clientHeight;
        }
        winHeight = winHeight * 0.94;
        $(".panel").css({"height": winHeight, "margin-bottom": 0});
        $(".panel-body").css({"height": winHeight * 0.94});
        onLoad();
        //BindEvent();
        //页面加载
        function onLoad() {
            //渲染树
            $('#left-tree').treeview({
                data: getTree(),
                levels: 1,
                showCheckbox: false//是否显示多选
            });
        }


        //获取树数据
        function getTree() {
            var tree = [
                {
                    text: "正在初始化目录树。。"
                    /*   id: "1",
                       nodes: [
                           {
                               text: "1  委托方要求设计方，按本合同要求",
                               id: "2",
                               nodes: [
                                   {
                                       text: "1.1  勘察设计服务"
                                   },
                                   {
                                       text: "1.2  勘察设计服"
                                   }
                               ]
                           },
                           {
                               text: "2.  本合同组成文件及其顺序"
                           }
                       ]*/
                }/*,
         */
            ];
            return tree;
        }
    });


</script>
<script>
    $(function () {

        $.post(requestUrl+"/showModel", {"id": modelId}, function (data) {
            $("#content").html(data.content);
        });
        $.post(requestUrl+"/showTree", {"modelId": modelId}, function (data) {
            $('#left-tree').treeview({
                data: data,
                levels: 1,
                onNodeSelected: function (event, node) {
                    $('#editName').val(node.text);
                    //  在这里添加隐藏表单字段
                    $("input[name=itemIndex]").val(node.id);
                    $.post(requestUrl+"/risk/showOne", {"itemIndex": node.id}, function (data) {
                        $("#item").prop("checked", true);
                        $("textarea").val("");
                        if (data != null) {
                            $("input[name=riskId]").val(data.riskId);
                            $("input[name=itemName]").val(data.itemName);
                            if (data.adviseRe != null && data.adviseRe != "") {
                                $("textarea").val(data.adviseRe);
                                $("#item").prop("checked", true);
                            }
                            if (data.performance != null && data.performance != "") {
                                $("textarea").val(data.performance);
                                $("#prop").prop("checked", true);
                            }
                            if (data.subjectReview != null && data.subjectReview != "") {
                                $("textarea").val(data.subjectReview);
                                $("#subj").prop("checked", true);
                            }
                        }
                    });
                },
                showCheckbox: false//是否显示多选
            });
        })
    });

    $(document).ready(function () {
        $(".summernote").summernote({lang: "zh-CN"})
    });
    var edit = function () {
        $("#eg").addClass("no-padding");
        $(".click2edit").summernote({lang: "zh-CN", focus: true})
    };
    var save = function () {
        $("#eg").removeClass("no-padding");
        var aHTML = $(".click2edit").code();
        $(".click2edit").destroy()
    };
</script>
</body>
</html>